package com.wwdx;

import com.wwdx.service.*;
import com.wwdx.service.impl.*;
import com.wwdx.wechat.config.merchant.MerchantWxMpConfig;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.*;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author liguoliang
 * @date 2018/5/20 17:02
 */
public abstract class BaseCommons {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    protected ThreadPoolTaskExecutor taskExecutor;
    @Resource
    protected FirstWxOpenService wxOpenService;
    @Resource
    protected MerchantWxService merchantWxService;
    @Resource
    protected MerchantWxEntPayService merchantWxEntPayService;
    @Resource
    protected MerchantWxPayService merchantWxPayService;
    @Resource
    protected MerchantWxMpConfig wxMerchantMpConfig;
    @Resource
    protected WwdxThemeServiceI wwdxThemeService;
    @Resource
    protected ProductServiceI productService;
    @Resource
    protected WwdxBookServiceI wwdxBookService;
    @Resource
    protected WwdxBookClassifyServiceI wwdxBookClassifyService;
    @Resource
    protected PayServiceI payService;
    @Resource
    protected WwdxBannerServiceI wwdxBannerService;
    @Resource
    protected WwdxBookChapterServiceI wwdxBookChapterService;
    @Resource
    protected TemplateMsgTaskServiceI templateMsgTaskService;
    @Resource
    protected WwdxVipUserServiceI wwdxVipUserService;
    @Resource
    protected WwdxVipProductServiceI wwdxVipProductService;
    @Resource
    protected MerchantOrderServiceI merchantOrderService;
    @Resource
    protected WechatPublishServiceI wechatPublishService;
    @Resource
    protected WwdxCopywriterServiceI wwdxCopywriterService;
    @Resource
    protected WwdxWeixinUserServiceI wwdxWeixinUserService;
    @Resource
    protected WwdxOpenAuthServiceI wwdxOpenAuthService;
    @Resource
    protected WwdxCommentServiceI wwdxCommentService;
    @Resource
    protected UserServiceI userService;
    @Resource
    protected RedisTemplate<String,Object> redisTemplate;
    @Resource(name = "redisTemplate")
    protected ValueOperations<String,Object> valueOperations;
    @Resource(name = "redisTemplate")
    protected HashOperations<String,String,Object> hashOperations;
    @Resource(name = "redisTemplate")
    protected ListOperations<String,Object> listOperations;
    @Resource(name = "redisTemplate")
    protected SetOperations<String,Object> setOperations;
    @Resource(name = "redisTemplate")
    protected ZSetOperations<String,Object> zSetOperations;
    @Value("#{constantProperties['directory']}")
    protected String directory;
    @Value("#{constantProperties['wechat_url']}")
    protected String wechatUrl;
    @Value("#{constantProperties['domain']}")
    protected String domain;
    @Value("#{constantProperties['pic_url']}")
    protected String picUrl;

    /**
     * 获取系统订单号
     */
    protected String makeOrderNum() {
        String key = "merchant:order:id";
        String time = new DateTime().toString("yyyyMMdd");
        return time + String.format("%1$020d", valueOperations.increment(key, 1));
    }

    /**
     * 32位随机数
     */
    protected String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}